package com.wxlgroup.springboot.exception;
import com.wxlgroup.springboot.commons.Response;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
/**
 * @auther:wxl
 * @Date:2022/5/24-05-24-19:42
 * @Description:com.wxlgroup.springboot.exception
 * @Version:1.0
 */

@ControllerAdvice
public class MyExceptionHandler {

    /**
     * 如果抛出的的是ServiceException，则调用该方法
     * @param se 业务异常
     * @return Response
     */
    @ExceptionHandler(ServiceException.class)
    @ResponseBody
    public Response handle(ServiceException se){
        return new Response(se.getCode(),null,se.getMessage());
    }
}
